from typing import List, Dict
import time


class SimpleScheduler:
    """简化版调度器"""

    def __init__(self, max_batch_size: int = 4):
        self.max_batch_size = max_batch_size
        self.waiting_requests: List[Dict] = []
        self.active_requests: Dict[str, Dict] = {}

    def add_request(self, request: Dict):
        """添加请求"""
        self.waiting_requests.append(request)

    def schedule(self) -> List[Dict]:
        """调度请求"""
        # 将等待的请求移到活跃状态
        while self.waiting_requests and len(self.active_requests) < self.max_batch_size:
            request = self.waiting_requests.pop(0)
            request['start_time'] = time.time()
            self.active_requests[request['id']] = request

        return list(self.active_requests.values())

    def complete_request(self, request_id: str):
        """完成请求"""
        if request_id in self.active_requests:
            request = self.active_requests.pop(request_id)
            request['end_time'] = time.time()
            request['duration'] = request['end_time'] - request['start_time']
            return request
        return None